<?php

//Enbart om kerberos-kdc är installerad
if( is_dir( '/etc/krb5kdc' ) ) {
    if ((isset($_POST['password']) AND isset($_POST['password2'])) AND $_POST['password']) {
        $name = $_POST['cn'];

        if ($_POST['password'] == $_POST['password2']) {
            $pw = $_POST['password'];

            //byter kerberoslösen med kadmin.local
            $descriptorspec = array(
               0 => array("pipe", "r"),  // stdin
               1 => array("pipe", "w"),  // stdout
               2 => array("pipe", "w")   // stderr
            );
            $process = proc_open('exec /usr/sbin/kadmin.local -q "cpw '.$name.'"', $descriptorspec, $pipes, "/");
            fwrite($pipes[0], $pw . "\n");
            fwrite($pipes[0], $pw . "\n");
            $stout_str = stream_get_contents($pipes[1]);
            $sterr_str = stream_get_contents($pipes[2]);
            fclose($pipes[0]);
            fclose($pipes[1]);
            fclose($pipes[2]);
            $exitCode = proc_close($process);
            if( $exitCode !== 0 && strlen($sterr_str) !== 0 ) {
                    //echo "FAIL: $stout_str\n$sterr_str\n";
                    error('unknown');
            }
        }
    }
}
?>
